package org.breezeiot.protodecode.enums;

/**
 * 国网终端应用层控制码
 *
 * @author zoe
 */
public enum GwAfnEnum {
    AFN_CONFIRM_CMD(0x0, "确认命令"),
    AFN_RESET_CMD(0x1, "复位命令"),
    AFN_LINKED_CHECK(0x2, "链路检测"),
    AFN_SETUP_PARAM(0x4, "设置参数"),
    AFN_CONTROL_CMD(0x5, "控制命令"),
    AFN_CALL_PARAM(0xA, "查询参数"),
    AFN_RTU_CONFIG(0x9, "请求终端配置及信息"),
    AFN_REQ_TASK_DATA(0xB, "请求任务数据"),
    AFN_REQ_1ST_DATA(0xC, "请求1类数据"),
    AFN_REQ_2ND_DATA(0xD, "请求2类数据"),
    AFN_REQ_3RD_DATA(0xE, "请求3类数据"),
    AFN_DATA_TRANSMIT(0x10, "透明转发");

    private final int value;
    private final String text;

    GwAfnEnum(int value, String text) {
        this.value = value;
        this.text = text;
    }

    public int getValue() {
        return value;
    }

    public String getText() {
        return text;
    }

    public Short getShortValue() {
        Integer obj = value;
        return obj.shortValue();
    }

    /**
     * 通过传入的字符串匹配枚举，传入值
     *
     * @param value
     * @return
     */
    public static GwAfnEnum getEnmuByValue(int value) {
        for (GwAfnEnum at : GwAfnEnum.values()) {
            if (at.getValue() == value) {
                return at;
            }
        }
        return null;
    }

    /**
     * 通过传入的字符串匹配枚举获得描述，传入值
     *
     * @param value
     * @return
     */
    public static String getText(int value) {
        GwAfnEnum type = getEnmuByValue(value);
        return type == null ? "" : type.text;
    }

}
